unit UPharmacyStockCount;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, AdvPanel, cxGraphics,
  cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit,
  dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel,
  dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue, cxGroupBox, DBAdvGlowNavigator,
  cxStyles, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage,
  cxNavigator, Data.DB, cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, UDMPharmacy,
  cxDBLookupComboBox;

type
  TFPharmacyStockCount = class(TForm)
    AdvPanelStyler1: TAdvPanelStyler;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1pricing_id: TcxGridDBColumn;
    cxGrid1DBTableView1item_count: TcxGridDBColumn;
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPharmacyStockCount: TFPharmacyStockCount;

implementation

{$R *.dfm}

procedure TFPharmacyStockCount.FormActivate(Sender: TObject);
  var
    pricingID : integer;
    itemCount : integer;
    i : integer;
begin

    itemCount := DMPharmacy.his_pharmacy_stock.RecordCount;

    DMPharmacy.his_pharmacy_stock.First;
    for i := 0 to itemCount - 1 do
    BEGIN
      pricingID := DMPharmacy.his_pharmacy_stock.FieldByName('parmacy_stock_id').Value;
      if DMPharmacy.his_pharmacy_stock_count.Locate('pricing_id',pricingID, [loPartialKey]) = False then
      BEGIN
        DMPharmacy.his_pharmacy_stock_count.Insert;
        DMPharmacy.his_pharmacy_stock_count.FieldByName('pricing_id').Value := DMPharmacy.his_pharmacy_stock.FieldByName('parmacy_stock_id').Value;
        DMPharmacy.his_pharmacy_stock_count.FieldByName('item_count').Value := DMPharmacy.his_pharmacy_stock.FieldByName('qty_in_stock').Value;
        DMPharmacy.his_pharmacy_stock_count.Post;
        DMPharmacy.his_pharmacy_stock_count.RefreshRecord;
      END;
      DMPharmacy.his_pharmacy_stock.Next;
    END;
end;

end.
